package cn.linshu.shiro.jwt.dto;

import cn.linshu.shiro.jwt.dto.IErrorCode;

/**
 * -*- coding: utf-8 -*-
 *
 * @Author linnin
 * @Name springboot3-labs-master
 * @Time 2025/2/3 23:43
 * @Note
 * @For
 * @Out Copyright© 2025 linnin
 */
public enum ResultCode implements IErrorCode {
    SUCCESS(200, "操作成功"),
    FAILED(500, "操作失败"),
    VALIDATE_FAILED(404, "参数检验失败"),
    UNAUTHORIZED(401, "暂未登录或token已经过期"),
    FORBIDDEN(403, "没有相关权限"),
    USER_NOT_FOUND(400001, "用户不存在"),
    PASSWORD_INCORRECT(400002, "密码不正确"),
    ACCOUNT_DISABLED(400003, "帐号已被禁用"),
    ;
    private long code;
    private String message;

    private ResultCode(long code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public long getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    // 根据状态码获取对应的枚举对象
    public static ResultCode getByCode(long code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode() == code) {
                return resultCode;
            }
        }
        return null;
    }
}
